package com.sky.controller.admin;

import com.sky.dto.*;
import com.sky.entity.Category;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.CategoryService;
import com.sky.service.OrderService;
import com.sky.vo.OrderVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


@RestController("adminOrderController")
@RequestMapping("/admin/order")
@Api(tags = "订单相关接口")
@Slf4j
public class OrderController {

    @Autowired
    private OrderService orderService;
    /**
     * 订单列表
     */
    @GetMapping("/list")
    @ApiOperation("订单列表")
    public  Result<PageResult> list(OrdersPageQueryDTO ordersPageQueryDTO){
        log.info("订单列表");
       PageResult result = orderService.list(ordersPageQueryDTO);
        return Result.success(result);
    }

    /**
     * 订单详情
     * @param orderId
     * @return
     */
    @GetMapping("/detail")
    @ApiOperation("订单详情")
    public Result<OrderVO> getOrderDetail(Long orderId){
        log.info("订单详情");
        OrderVO orderVO = orderService.getOrderDetail(orderId);
        return Result.success(orderVO);
    }

    /**
     * 订单状态改变
     * @param ordersConfirmDTO
     * @return
     */
    @PutMapping("/updateStatus")
    @ApiOperation("订单状态改变")
    public Result updateStatus(@RequestBody  OrdersConfirmDTO ordersConfirmDTO){
        log.info("订单状态改变");
        orderService.updateStatus(ordersConfirmDTO);
        return Result.success();

    }
    @PutMapping("/cancel")
    @ApiOperation("取消订单")
    public Result cancelOrder(@RequestBody  OrdersCancelDTO ordersCancelDTO) {
        log.info("取消订单");
        orderService.cancelOrder(ordersCancelDTO);
        return Result.success();
    }

    @PutMapping("/reject")
    @ApiOperation("拒绝订单")
    public Result rejectOrder(@RequestBody  OrdersConfirmDTO ordersConfirmDTO) {
        log.info("取消订单");
        orderService.rejectOrder(ordersConfirmDTO);
        return Result.success();
    }

}
